﻿using CommunityToolkit.Mvvm.Messaging;
using Messenger.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Messenger.ViewModels;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Messenger.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : UserControl
    {
        public MainView()
        {
            InitializeComponent();
            WeakReferenceMessenger.Default.Register<LogSuccess>(this,Receive);
        }

        private void Receive(object recipient, LogSuccess message)
        {
            Dispatcher.Invoke(() =>
            {
                UserName.Text = $"Welcom {message.userName}";
                Password.Text = $"Password is {message._password}";
            });
            message.Reply("User profile updated");
        }

        //继承IRecipient(LogSuccess)时使用下列代码
        /*public void Receive(LogSuccess message)
        {
            Dispatcher.Invoke(() =>
            {
                UserName.Text = $"Welcom {message.userName}";
                Password.Text = $"Password is {message._password}";
            });
            message.Reply("User profile updated");
        }*/
    }
}
